using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightToolbox
{
    internal class RTLTextBlock : Control
    {
        private TextBlock _internalTextBlock = null;
        public RTLTextBlock()
        {
            System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("SilverlightRTLControls.RTLTextBlock.xaml");
            FrameworkElement elem = this.InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd());
            Canvas parent = elem as Canvas;
            _internalTextBlock = parent.Children[0] as TextBlock;
        }

        private string _text;
        public string Text
        {
            get
            {
                return InternalTextBlock.Text;
            }
            set
            {
                if (InternalTextBlock.Text != NBidi.NBidi.LogicalToVisual(value))
                {
                    _text = NBidi.NBidi.LogicalToVisual(value);
                    InternalTextBlock.Text = _text;
                }
            }
        }

        internal TextBlock InternalTextBlock
        {
            get
            {
                return _internalTextBlock;
            }
        }

        public TextBlock TextBlock
        {
            get
            {
                return _internalTextBlock;
            }
        }

        public double ActualHeight
        {
            get
            {
                return InternalTextBlock.ActualHeight;
            }
        }

        public double ActualWidth
        {
            get
            {
                return InternalTextBlock.ActualWidth;
            }
        }

        public string FontFamily
        {
            get
            {
                return InternalTextBlock.FontFamily;
            }
            set
            {
                InternalTextBlock.FontFamily = value;
            }
        }


        public double FontSize
        {
            get
            {
                return InternalTextBlock.FontSize;
            }
            set
            {
                InternalTextBlock.FontSize = value;
            }
        }

        //public FontStretches FontStretch
        //{
        //    get
        //    {
        //        return InternalTextBlock.FontStretch;
        //    }
        //    set
        //    {
        //        InternalTextBlock.FontStretch = value;
        //    }
        //}

        public string FontStretchString
        {
            get
            {
                return InternalTextBlock.FontStretch.ToString();
            }
            set
            {
                if (Enum.IsDefined(typeof(FontStretches), value))
                    InternalTextBlock.FontStretch = (FontStretches)Enum.Parse(typeof(FontStretches), value, true);
                else
                    System.Diagnostics.Debug.WriteLine(string.Format("{0} is not a valid {1} enum", value, "FontStretchs"));
            }
        }

        //public FontStyles FontStyle
        //{
        //    get
        //    {
        //        return InternalTextBlock.FontStyle;
        //    }
        //    set
        //    {
        //        InternalTextBlock.FontStyle = value;
        //    }
        //}


        public string FontStyleString
        {
            get
            {
                return InternalTextBlock.FontStyle.ToString();
            }
            set
            {
                if (Enum.IsDefined(typeof(FontStyles), value))
                    InternalTextBlock.FontStyle = (FontStyles)Enum.Parse(typeof(FontStyles), value, true);
                else
                    System.Diagnostics.Debug.WriteLine(string.Format("{0} is not a valid {1} enum", value, "FontStyles"));
            }
        }

        //public FontWeights FontWeight
        //{
        //    get
        //    {
        //        return InternalTextBlock.FontWeight;
        //    }
        //    set
        //    {
        //        InternalTextBlock.FontWeight = value;
        //    }
        //}

        public string FontWeightString
        {
            get
            {
                return InternalTextBlock.FontWeight.ToString();
            }
            set
            {
                if (Enum.IsDefined(typeof(FontWeights), value))
                    InternalTextBlock.FontWeight = (FontWeights)Enum.Parse(typeof(FontWeights), value, true);
                else
                    System.Diagnostics.Debug.WriteLine(string.Format("{0} is not a valid {1} enum", value, "FontWeights"));
            }
        }


        //public TextDecorations TextDecorations
        //{
        //    get
        //    {
        //        return InternalTextBlock.TextDecorations;
        //    }
        //    set
        //    {
        //        InternalTextBlock.TextDecorations = value;
        //    }
        //}

        public string TextDecorationsString
        {
            get
            {
                return InternalTextBlock.TextDecorations.ToString();
            }
            set
            {
                if (Enum.IsDefined(typeof(TextDecorations), value))
                    InternalTextBlock.TextDecorations = (TextDecorations)Enum.Parse(typeof(TextDecorations), value, true);
                else
                    System.Diagnostics.Debug.WriteLine(string.Format("{0} is not a valid {1} enum", value, "TextDecorations"));
            }
        }


        //public TextWrapping TextWrapping
        //{
        //    get
        //    {
        //        return InternalTextBlock.TextWrapping;
        //    }
        //    set
        //    {
        //        InternalTextBlock.TextWrapping = value;
        //    }
        //}

        public string TextWrappingString
        {
            get
            {
                return InternalTextBlock.TextWrapping.ToString();
            }
            set
            {
                if (Enum.IsDefined(typeof(TextWrapping), value))
                    InternalTextBlock.TextWrapping = (TextWrapping)Enum.Parse(typeof(TextWrapping), value, true);
                else
                    System.Diagnostics.Debug.WriteLine(string.Format("{0} is not a valid {1} enum", value, "TextWrapping"));
            }
        }

        public string ForegroundString
        {
            get
            {
                return InternalTextBlock.Foreground.ToString();
            }
            set
            {
                throw new NotImplementedException("Use foreground attribute programmaticly");
            }
        }


        //public Brush Foreground
        //{
        //    get
        //    {
        //        return InternalTextBlock.Foreground;
        //    }
        //    set
        //    {
        //        InternalTextBlock.Foreground = value;
        //    }
        //}


    }
}